package com.huangguolin.cloud.api.user.service.impl;

import com.huangguolin.cloud.api.user.entity.ApiUserEntity;
import com.huangguolin.cloud.api.user.repository.ApiDao;
import com.huangguolin.cloud.api.user.service.ApiUserService;
import com.huangguolin.cloud.mybatis.entity.PtIndividualEntity;
import com.huangguolin.cloud.mybatis.entity.PtUserEntity;
import com.huangguolin.cloud.mybatis.flexigrid.PagingEntity;
import com.huangguolin.cloud.spring.util.MailUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
public class ApiUserServiceImpl implements ApiUserService {
    @Resource
    private ApiDao apiDao;

    @Resource
    private HttpSession session;

    @Override
    public void register(String userName, String passWord, String identity, String phone, String email) {
        apiDao.register(userName, passWord, identity, phone, email);
    }

    @Override
    public List<PtUserEntity> login(String userName, String passWord) {
        List<PtUserEntity> list = apiDao.login(userName, passWord);
        return list;
    }


    /**
     * 发送邮箱验证码
     * @param emailCode 用户邮箱账号
     */
    @Override
    public void getemailcode(String emailCode) {
        String code = MailUtil.getEmailcode(emailCode);
        session.setAttribute("code", code);//邮箱验证码
    }

    /**
     * 分页查询用户列表
     *
     * @param paging
     * @param entity
     * @return
     */
    @Override
    public List<PtUserEntity> queryUserList(PagingEntity paging, ApiUserEntity entity) {
        return apiDao.queryUserList(paging, entity);
    }

    @Override
    public Integer queryUserTotal(ApiUserEntity entity) {
        return apiDao.queryUserTotal(entity);
    }

    @Override
    public void personalInformation(String userUuid, String userName, String gender, String birthday, String signature, String occupation, String firm, String hometown, String phone, String email, String personalInstructions) {
        apiDao.personalInformation(userUuid, userName, gender, birthday, signature, occupation, firm, hometown, phone, email, personalInstructions);
    }

    @Override
    public String query(String userName, String passWord) {

        return apiDao.query(userName, passWord);
    }

    @Override
    public List<PtIndividualEntity> queryUser(String userUuid) {
        List<PtIndividualEntity> list = apiDao.queryUser(userUuid);
        return list;
    }

    @Override
    public void revise(String userUuid, String userName, String gender, String birthday, String signature, String occupation, String firm, String hometown, String phone, String email, String personalInstructions) {
        apiDao.revise(userUuid, userName, gender, birthday, signature, occupation, firm, hometown, phone, email, personalInstructions);
    }

    @Override
    public void reviseTea(String userName, String nickname, String password, Integer sex, Integer level, String phone, String email, String introduction,String photo) {
        apiDao.reviseTea(userName,nickname,password,sex,level, phone, email, introduction,photo);
    }

    @Override
    public void forget(String userName, String passWord) {
        apiDao.forget(userName, passWord);
    }

    @Override
    public void deleteUser(String userUuids) {
        String[] userIdArray = userUuids.split(",");
        apiDao.deleteUser(userIdArray);
    }

    @Override
    public List<PtUserEntity> queryUserTeacherList(PagingEntity paging, ApiUserEntity entity) {
        return apiDao.queryUserTeacherList(paging, entity);
    }

    @Override
    public Integer queryUserTeacherTotal(ApiUserEntity entity) {
        return apiDao.queryUserTeacherTotal(entity);
    }

    @Override
    public List<PtUserEntity> queryUserStudentList(PagingEntity paging, ApiUserEntity entity) {
        return apiDao.queryUserStudentList(paging, entity);
    }

    @Override
    public Integer queryUserStudentTotal(ApiUserEntity entity) {
        return apiDao.queryUserStudentTotal(entity);
    }

    @Override
    public void deleteUserTea(String phone) {
        String[] userPhoneArray = phone.split(",");
        apiDao.deleteUserTea(userPhoneArray);
    }
    @Override
    public void deleteUserStu(String phone) {
        String[] userPhoneArray = phone.split(",");
        apiDao.deleteUserStu(userPhoneArray);
    }
    @Override
    public List<PtUserEntity> queryUserTea(String phone) {
        List<PtUserEntity> list = apiDao.queryUserTea(phone);
        return list;
    }

    @Override
    public void AddUserTea(String userName, String nickname, String password, Integer sex, Integer level, Integer role, String phone, String email, String introduction,String photo) {
        apiDao.AddUserTea(userName,nickname,password,sex,level,role, phone, email, introduction,photo);
    }

    @Override
    public void PlusUser(String userName, String nickName, String password, Integer id, String phone, String email, String qqNumber, String signature,String introduction) {
        apiDao.PlusUser(userName,nickName,password,id,phone,email,qqNumber,introduction,signature);
    }
}